LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 11-08-2009, 09:22 AM   #1
Raymii
LQ Newbie
 
Registered: Nov 2009
Posts: 1

Rep: Reputation: 0
[bash] Current time to degrees for clock wallpaper


I'm trying to make a script which transforms the current time into a clock image.
I'm doing it with imagemagick and bash. What I already have is a script which makes the clock from out nothing:
http://raymii.org/test/clock.sh
(It looks like: http://raymii.org/test/clock.png )
But now the time has to be shown with hands.
What I was thinking is to call the script from a crontab every minute.
It then takes the current time with the date command, strips it so that the HHSS is left (with sed maybe). Then it makes a line with convert that is in the angle it should according to the current time(The Minute hand) and it does that also for the hour hand. Then it composites it all together.

I have a center dot, and the hands should come out of it. In the script I'm using percentages because the plan is to make it work at 1280x1024 and 1920x1280.

But the whole date to hand conversion part is to difficult for me. I totally do not know how to do that.

My bash skills are limited, and what I have can probably be done better, so i'd love some tips and suggestions. Especially for the time to hand part.
 
Old 11-08-2009, 12:37 PM   #2
slimm609
Member
 
Registered: May 2007
Location: Chas, SC
Distribution: slackware, gentoo, fedora, LFS, sidewinder G2, solaris, FreeBSD, RHEL, SUSE, Backtrack
Posts: 420

Rep: Reputation: 62
MINHAND and HRHAND will give the proper degrees for hands.

i just havent used imagemagick enough to draw out the hands.

hope this helps

Code:
HR=`date +%l`
MIN=`date +%M`
#convert minutes to give the proper angle for hour
M4H=`echo "$MIN * 1.666666" | bc`
if [ "$HR" = "12" ]; then
   HRHAND=`echo "($HR.$M4H * 30) - 360" | bc`
else 
   HRHAND=`echo "$HR.$M4H * 30" | bc`
fi
MINHAND=`echo "$MIN * 6" | bc`
 
Old 11-10-2009, 06:01 PM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Puppy
Posts: 3,048

Rep: Reputation: 95
it's easy.

360 degrees in a circle, 60 minutes in a circle.

1 minute = 6 degrees.

cron is not accurate. I really wouldn't.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash: display CURRENT time in prompt? exscape Linux - Software 8 04-09-2011 09:55 PM
hardware clock time differs from system time after setting maxgsp Linux - Software 2 02-28-2009 07:15 AM
clock-adjustment time is offseet from clock-display time bezdomny Linux - Desktop 2 11-19-2008 02:48 PM
Where does RH8 daily set system time to hardware clock time smartnorman Red Hat 1 05-24-2006 02:42 PM
Various clock issues: Clock shows wrong time only in Knoppmyth, & CMOS time change ? davidbix General 1 04-05-2006 09:58 PM


All times are GMT -5. The time now is 02:45 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration